var myvue = new Vue({
	el: "body",
	data: {
		userid: "",
		money: "",
		integral: 0
	},
	created: function() {
		this.leancloudinit();
	},
	methods: {
		backpage: function() {
			history.back();
		},
		leancloudinit: function() {
			var _this = this;
			var APP_ID = 'c4w6bVvWfh8xxcmkBE1G0gIt-gzGzoHsz';
			var APP_KEY = 'JBikg4Ksk76zcTi5BKYWvTJF';
			AV.init({
				appId: APP_ID,
				appKey: APP_KEY
			});
			var phonenum = AV.User.current().attributes.username;
			var query = new AV.Query('ELM_user');
			query.contains('phonenum', '' + phonenum + '');
			query.find().then(function(data) {
				_this.userid = data[0].id;
				_this.money = data[0].attributes.money;
				_this.integral = eval(data[0].attributes.integral);
			}, function(error) {
				// 异常处理
			});
		},
		dhjf: function() {
			var userid = this.userid;
			var money = this.money;
			var integral = this.integral;
			var dhmoney = ((integral / 10) + (money * 1)).toString();
			if(integral>0) {
				// 第一个参数是 className，第二个参数是 objectId
				var todo = AV.Object.createWithoutData('ELM_user', userid);
				// 修改属性
				todo.set('money', dhmoney);
				todo.set('integral', '0');
				// 保存到云端
				todo.save().then(function() {
					myvue.integral = 0;
					alert("兑换成功，请到余额查询");
				})
			}else{
				alert("您的积分不足以兑换！");
			}

		}
	}
})